function request(url, method, data) {
	// const baseUrl = 'http://185.232.92.15:3433';
	const baseUrl = 'http://127.0.0.1:3433';
	const urlWithBase = baseUrl + url;

	return new Promise(async (resolve, reject) => {
		try {
			uni.showLoading({
				title: '加载中...'
			});

			const response = await uni.request({
				url: urlWithBase,
				method: method,
				data: data,
				header: {
					'X-Requested-With': 'XMLHttpRequest',
					'Content-Type': 'application/json; charset=UTF-8',
					"Accept": "*/*"
				},
				dataType: 'json'
			});
			uni.hideLoading(); // 隐藏加载状态

			const successRange = (response.data.code >= 200 && response.data.code <= 2000) ||
				(response.data.code >= 2001 && response.data.code <= 2009);

			if (successRange) {
				resolve(response.data);
			} else {
				reject(new Error('Request failed with status: ' + response.data.code));
			}
		} catch (error) {
			uni.hideLoading(); // 隐藏加载状态
			reject(error);
		}
	});
}

export default {
	async get(url, data) {
		try {
			const response = await request(url, 'GET', data);
			return response;
		} catch (error) {
			uni.hideLoading(); // 隐藏加载状态
			// 处理请求失败的情况
			console.error('GET request failed:', error);
			throw error;
		}
	},
	async post(url, data) {
		try {
			const response = await request(url, 'POST', data);
			return response;

		} catch (error) {
			uni.hideLoading(); // 隐藏加载状态
			// 处理请求失败的情况
			console.error('GET request failed:', error);
			throw error;
		}
	}
	// 可以添加更多请求类型的方法，如 PUT、DELETE，根据需要进行扩展
}